package com.wyx.httpService.jinyeService;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;

/**
 * username: 140105122422
 * password: T4X3L3qN1T+N0v8UjDKvUw==
 * verifycode: YE83
 * csrfToken: p3f2oQgtjhHGyWzrYoK1BneTpZWKNa2vAIj6Pgjr258=
 */
public class LoginEntry {
    private String username;
//    加密之后的password
    private String password;
    private String  verifycode;
    private String csrfToken;

    public LoginEntry(String username, String password, String verifycode, String csrfToken) {
        this.username = username;
        this.password = password;
        this.verifycode = verifycode;
        this.csrfToken = csrfToken;
    }

    public LoginEntry() {
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getVerifycode() {
        return verifycode;
    }

    public void setVerifycode(String verifycode) {
        this.verifycode = verifycode;
    }

    public String getCsrfToken() {
        return csrfToken;
    }

    public void setCsrfToken(String csrfToken) {
        this.csrfToken = csrfToken;
    }

    @Override
    public String toString() {
        return "loginEntry{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", verifycode='" + verifycode + '\'' +
                ", csrfToken='" + csrfToken + '\'' +
                '}';
    }

    public static String eba(String password) {
        try {
            String key = "yourKey"; // 设置密钥

            SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");

            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

            byte[] encrypted = cipher.doFinal(password.getBytes());

            return Base64.getEncoder().encodeToString(encrypted);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        String password = "@Wy123456"; // 要加密的密码
        String encryptedPassword = eba(password);
        System.out.println("Encrypted Password: " + encryptedPassword);
    }

}
